/**
 * @author Administrator
 */
// 砖块基本类
function Brick(pV, bR){
	var _this = this;
	Sprite.call(_this, pV, bR);
	_this.img = undefined;
	_this.name = undefined;
	_this.physicsNode = undefined;
}
inheritPrototype(Brick, Sprite);


//静止的砖块类
function StaticBrick(pV, bR){
	var _this = this;
	Brick.call(_this, pV, bR);
    _this.draw = function(canvas)
	{
		var context = canvas.getContext("2d");
		context.drawImage(_this.img, _this.position.x, _this.position.y);		
	}
	
	_this.update = function()
	{
		_this.position.x = _this.physicsNode.position.x;
		_this.position.y = _this.physicsNode.position.y;
	}
	
	_this.touch = function()
	{
	}
	
	var init = function()
	{		
	   	_this.name = "staticBrick";
	   	var V = new Vector2();
	   	V.x = pV.x;
	   	V.y = pV.y;
		_this.physicsNode = new PhysicsNode(V, bR, new Vector2(0, 0), new Vector2(0, 0));
	}
	init();
}
inheritPrototype(StaticBrick, Brick);


//移动的砖块类
function MovingBrick(pV, bR){
	var _this = this;
	Brick.call(_this, pV, bR);
    _this.draw = function(canvas)
	{
		var context = canvas.getContext("2d");
		context.drawImage(_this.img, _this.position.x, _this.position.y);		
	}
	
	_this.update = function()
	{
		_this.position.x = _this.physicsNode.position.x;
		_this.position.y = _this.physicsNode.position.y;
		var x = 480 - _this.box.width;
		if( _this.position.x > x )
		{
			_this.position.x = x;
			_this.physicsNode.velocity.x = -_this.physicsNode.velocity.x;
		}else if( _this.position.x < 0)
		{
			_this.position.x = 0;
			_this.physicsNode.velocity.x = -_this.physicsNode.velocity.x;
		}
	}

	_this.touch = function()
	{
	}
	
	var init = function()
	{		
	   	_this.name = "movingBrick";
	   	var V = new Vector2();
		V.x = pV.x;
	   	V.y = pV.y;
		_this.physicsNode = new PhysicsNode(V, bR, new Vector2(2, 0), new Vector2(0, 0));
	}
	init();
}
inheritPrototype(MovingBrick, Brick);

//裂开的砖块类
function CrackedBrick(pV, bR){
	var _this = this;
	Brick.call(_this, pV, bR);
	_this.imgIndex = 0;
    _this.draw = function(canvas)
	{
		var context = canvas.getContext("2d");
		context.drawImage(_this.img[_this.imgIndex], _this.position.x, _this.position.y);		
	}
	
	_this.update = function()
	{	
		_this.position.x = _this.physicsNode.position.x;
		_this.position.y = _this.physicsNode.position.y;
	}
	
	_this.touch = function()
	{
		_this.imgIndex = 1;
		_this.physicsNode.velocity.y = 10;
	}
	
	var init = function()
	{
		_this.img = new Array();		
		_this.imgIndex = 0;
	   	_this.name = "crackedBrick";
	   	var V = new Vector2();
		V.x = pV.x;
	   	V.y = pV.y;
		_this.physicsNode = new PhysicsNode(V, bR, new Vector2(0, 0), new Vector2(0, 0));
	}
	init();
}
inheritPrototype(CrackedBrick, Brick);



